import React, {Component, PropTypes} from 'react';
import styles from './Main.less';
import SearchTableComponent from '../Table/SearchTableComponent';
import {getTableInfo} from "../../services/showServer";

function GetQueryString(name)
{
  var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if(r!=null)return  unescape(r[2]); return null;
}

class TableMainContainer extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    var id = GetQueryString("id");
    getTableInfo(id).then(function (json) {
      var meta = JSON.parse(json.tableMeta);
      var pColumns = [];
      var columns = [];
      if (meta.partitioned == 'true') {
        pColumns = meta.partitionColumns;
      }
      if (meta.columns != '') {
        columns = meta.columns;
      }

      this.refs.table.setState({
        remark: json.remark,
        comment: json.comment,
        editComment: json.comment,
        partitionColumns: pColumns,
        columnsFilter: columns,
        columns: columns,
        tableMeta: meta,
        table: json,
      });

    }.bind(this));
  }

  componentWillMount() {
  }

  componentWillUnmount() {
  }

  render() {
    return (
      <div className={styles.content}>
        <div className={styles.tableDetail_center}>
          {/*<TableDetailComtainer signal={this.signal} ref="tree"/>*/}
          <SearchTableComponent ref="table"/>
        </div>
      </div>
    );
  }
}

export default TableMainContainer;
